<template>
	<view>
		<cu-custom bgColor="bg-gradual-blue" :isBack="true">
			<block slot="backText">返回</block>
			<block slot="content">访客自助登记二维码</block>
		</cu-custom>

		<view class="cu-bar margin-top">
			<view class="action">
				<text class="text-red">
					温馨提示：长按下方二维码，分享给好友，好友可以通过识别二维码,进入访客自助登记页面
				</text>
			</view>
		</view>

<!--
		<view class="cu-bar bg-white margin-top solid-bottom">
			<view class="action">
				<text class="text-blue"></text>有效时间
			</view>
			<picker fields="day" mode="date" :start="enddate" :value="date" @change="bindDateChange">
				<view class="action">
					{{date}}
				</view>
			</picker>
		</view>
		<view class="cu-bar bg-white">
			<view class="action">
				<text class="text-blue"></text>有效次数
			</view>
			<view class="action">
				<view @click="plusNum">
					<uni-icons class="uni-icons-left" type="plus-filled" color="#007aff" size="20" />
				</view>
				<text class="input-num">{{num}}</text>
				<view @click="minusNum">
					<uni-icons type="minus-filled" color="#007aff" size="20" />
				</view>
			</view>
		</view>
		
		-->
		<view class="img-code-view">
			<image class="img-code" @tap="ViewImage" :src="$constant.IMG_VERSION == $constant.OSS?imgUrl:$constant.BASEURL+imgUrl" mode="aspectFit"></image>
		</view>
		<button @click="btnRefresh" type="" :disabled="refresh" class="margin cu-btn block bg-blue margin-tb-sm lg" :loading="refresh">刷新</button>
	</view>
</template>

<script>
	import uniIcons from '@/components/uni-icons/uni-icons.vue'
	import {
		formateDate
	} from "@/common/utils.js"
	let curDate = new Date() //获取当前日期
	export default {
		components: {
			uniIcons,
		},
		data() {
			return {
				date: formateDate(curDate, "Y-M-D"),
				enddate: formateDate(curDate, "Y-M-D"),
				num: 6,
				imgUrl: '',
				refresh: false
			}
		},
		onLoad() {
			this.VictorQRcode()
		},
		methods: {
			plusNum() {
				if (this.num < 8) {
					this.num++
				}
			},
			minusNum() {
				if (this.num > 0) {
					this.num--
				}
			},
			ViewImage() {
				let urls = [this.imgUrl]
				uni.previewImage({
					urls: urls,
					current: 0
				});
			},
			// 选择打卡日期
			bindDateChange: function(e) {
				this.date = e.target.value
			},
			btnRefresh() {
				this.VictorQRcode()
			},
			VictorQRcode() {
				this.refresh = true
				uni.showLoading({
					title: '加载中',
				})
				// var this
				uni.request({
					url: this.$constant.BASEURL + this.$constant.visitorRegister,
					method: 'POST',
					header: {
						'content-type': 'application/x-www-form-urlencoded'
					},
					data: {
						
						token: getApp().globalData.token,
						unitno: getApp().globalData.orgcode,
						url: 'https://kq.lsyat.com',
						
					},
					success: (res) => {
						console.log(res)
						if (res.data.code == 0) {
							this.imgUrl = res.data.data
						} else {
							uni.showModal({
								content: res.data.message,
								showCancel: false
							})
						}
					},
					complete: (res) => {
						this.refresh = false
						uni.hideLoading()
					}
				})
			}
		}
	}
</script>

<style>
	.input-num {
		width: 60upx;
		text-align: center;
	}

	.img-code-view {
		padding: 35upx;
		text-align: center;
	}
</style>
